import { createRouter, createWebHashHistory, RouteRecordRaw } from "vue-router";
import routes from "./routes";
import { tokenKey } from "../utils/constants"

const whiteList=["/login","/register","/demo"];

const router = createRouter({
	history: createWebHashHistory(),
	routes,
});

router.beforeEach((to, from, next) => {
	var token=window.localStorage.getItem(tokenKey);
	if(token){
		next();
	}else{		
		if(whiteList.indexOf(to.path)!==-1){
			next();
		}else{
			next("/login")
		}
	}
});
export default router;
